// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   apply_check_ok.java

package draft.purchase;

import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;

public class apply_check_ok extends HttpServlet
{

	public apply_check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		counter count = new counter(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		try
		{
			nseer_db_backup1 purchase_db = new nseer_db_backup1(dbApplication);
			if (purchase_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String apply_ID = request.getParameter("apply_ID");
				String config_ID = request.getParameter("config_ID");
				String designer = request.getParameter("designer");
				String register = request.getParameter("register");
				String register_time = request.getParameter("register_time");
				String register_id = request.getParameter("register_id");
				String bodyb = new String(request.getParameter("remark").getBytes("UTF-8"), "UTF-8");
				String remark = exchange.toHtml(bodyb);
				String product_id[] = request.getParameterValues("product_ID");
				String amount[] = request.getParameterValues("amount");
				int n = 0;
				for (int i = 0; i < product_id.length; i++)
					if (!validata.validata(amount[i]))
						n++;

				if (n == 0)
				{
					String sql = "";
					String sql8 = (new StringBuilder("select * from purchase_apply where apply_ID='")).append(apply_ID).append("' and (check_tag='9' or check_tag='5')").toString();
					ResultSet rs8 = purchase_db.executeQuery(sql8);
					if (rs8.next())
					{
						for (int i = 0; i < product_id.length; i++)
							if (!amount[i].equals(""))
							{
								sql = (new StringBuilder("update purchase_apply set amount='")).append(amount[i]).append("',designer='").append(designer).append("',register='").append(register).append("',register_time='").append(register_time).append("',remark='").append(remark).append("',register='").append(register).append("',register_time='").append(register_time).append("' where apply_ID='").append(apply_ID).append("' and product_id='").append(product_id[i]).append("'").toString();
								purchase_db.executeUpdate(sql);
							} else
							{
								sql = (new StringBuilder("delete from purchase_apply where apply_ID='")).append(apply_ID).append("' and product_id='").append(product_id[i]).append("'").toString();
								purchase_db.executeUpdate(sql);
							}

						List rsList = GetWorkflow.getList(purchase_db, "purchase_config_workflow", "05");
						if (rsList.size() == 0)
						{
							sql = (new StringBuilder("update purchase_apply set check_tag='1' where apply_ID='")).append(apply_ID).append("'").toString();
							purchase_db.executeUpdate(sql);
						} else
						{
							sql = (new StringBuilder("update purchase_apply set check_tag='0' where apply_ID='")).append(apply_ID).append("'").toString();
							purchase_db.executeUpdate(sql);
							for (Iterator ite = rsList.iterator(); ite.hasNext(); purchase_db.executeUpdate(sql))
							{
								String elem[] = (String[])ite.next();
								sql = (new StringBuilder("insert into purchase_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(apply_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
							}

						}
						response.sendRedirect("draft/purchase/apply_ok.jsp?finished_tag=4");
					} else
					{
						response.sendRedirect("draft/purchase/apply_ok.jsp?finished_tag=5");
					}
				} else
				{
					response.sendRedirect("draft/purchase/apply_ok.jsp?finished_tag=6");
				}
				purchase_db.commit();
				purchase_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
